<template>
	<view>
		<view class="search_input">
			<view class="uni-form-item uni-column">
				<input v-model="searchVal" class="uni-input" confirm-type="search" placeholder="请输入小说名或者作者名" @confirm="searchConfirm"/>
			</view>
		</view>
		<view class="search_data">
			<view v-for="(item, index) in bookList" :key="index" class="book_list" @click="gotoBookDetail(item)">
				<view class="book_img">
					<image style="width: 80px;height: 100px;" :src="item.bookImgUrl" />
				</view>
				<view class="book_text_list">
					<view class="book_name">
						<text>{{ item.bookName }}</text>
					</view>
					<view class="book_author">
						<text>{{ item.bookAuthor }}</text>
					</view>
					<view class="book_profile">
						<text>{{ item.bookProfile }}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				searchVal: '', // 搜索内容
				bookList: [] // 搜索到的书籍列表
			}
		},
		onLoad() {
	
		},
		methods: {
			// 搜索提交
			searchConfirm() {
				this.bookList = [];
				if (!this.searchVal) {
					uni.showToast({
						title: '请输入搜索内容!',
						icon: 'error',
						duration: 2000
					});
					return;
				}
				uni.showLoading({
					title: '查询中,请稍候...'
				});
				this.$api.get({
					url: '/app/bqg/searchBookOrAuthor',
					params: {
						params: this.searchVal
					}
				}).then(res => {
					// console.log('res', res);
					if (res && res.data.code === 0) {
						const datas = res.data.books;
						this.bookList = datas;
					}
					uni.hideLoading();
				}).catch(error => {
					uni.hideLoading();
				});
			},
			// 去详细书籍页面
			gotoBookDetail(item) {
				uni.navigateTo({
					url: '/pages/book/book-detail?bookWebUrl=' + item.bookWebUrl
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #d8d9da;
	}
	.search_input {
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		margin-left: 10rpx;
		margin-right: 10rpx;
		background: #ffffff;
	}
	
	.search_data {
		width: 100%;
		height: 100%;
		
		.book_list {
			display: flex;
			align-items: center;
			margin-bottom: 10rpx;
			background: #fef9ef;
			
			.book_img {
				margin-left: 10rpx;
				margin-top: 10rpx;
			}
			
			.book_text_list {
				margin-left: 10rpx;
				margin-right: 10rpx;
				font-size: 0.8rem;
				
				.book_name {}
				.book_author {}
				.book_profile {}
			}
		}
	}
</style>